<?php if (count($this->messages)) : ?>
	<div class="ms_message">
		<?php foreach ($this->messages as $message) : ?>
			<?php echo $this->translate($message); ?>
		<?php endforeach; ?>
	</div>
<?php endif; ?>
<?php if (count($this->paginator)): ?>
	<table class="sm_tbl_classic" id="list_store">
		<thead>
			<tr>
				<th style="width:300px;">
					<?php
					echo $this->partial('store/sortable_item_control.phtml', array(
						'column' => array(
							'sort_column' => 'store_name',
							'sort_default' => 'ASC'
						),
						'label' => 'TABLE_HEADER_NAME'
					))
					?>
				</th>
				<th style="width:200px;">
					<span>
						<?php echo $this->translate('TABLE_HEADER_FANPAGES') ?>
					</span>
				</th>
				<th>
					<?php
					echo $this->partial('store/sortable_item_control.phtml', array(
						'column' => array(
							'sort_column' => 'products',
							'sort_default' => 'DESC'
						),
						'label' => 'TABLE_HEADER_NUMBER_OF_PRODUCT'
					))
					?>
				</th>
				<th>
					<?php
					echo $this->partial('store/sortable_item_control.phtml', array(
						'column' => array(
							'sort_column' => 'status',
							'sort_default' => 'DESC'
						),
						'label' => 'TABLE_HEADER_STATUS'
					))
					?>
				</th>
				<th>
					<span>
						<?php echo $this->translate('TABLE_HEADER_ACTIONS') ?>
					</span>
				</th>
			</tr>
		</thead>
		<tbody>
	<?php
	foreach ($this->paginator->getCurrentItems() as $store):
		/* @var $store Core_Model_store */
		?>
			<tr>
				<td>
					<p>
						<a class="underline" href="<?php echo $this->url(array('controller' => 'product','action' => 'list', 'id_store' => $store->id, 'page' => null)); ?>">
							<?php echo $this->escape($store->name) ?>
						</a>
					</p>
				</td>
				<td>
					<?php
					$arrPages = array_combine(explode(',', $store->id_pages), explode(',', $store->page_name));
					echo $this->social->render('listFanpages', array('arrPages' => $arrPages, 'view' => $this));
					?>
				</td>
				<td>
					<div class="align-right-middle">
						<a class="underline tooltip"
							href="<?php echo $this->url(array('controller' => 'product', 'action' => 'list', 'page' => null, 'id_store' => $store->id))?>"
							title="<?php echo $this->translate('TABLE_HEADER_PRODUCT_TOOLTIP',$store->getNumberOfActiveProduct(),$store->getNumberOfAllProduct()) ?>"
						>
							<?php echo $store->getNumberOfActiveProduct() ?> / <?php echo $store->getNumberOfAllProduct()?>
						</a>
					</div>
				</td>
		<td>
            <div>
                <span class="tooltip_label" title="<?php echo $this->translate('TOOTIP_' . $store->getStatus());?>">
                    <?php echo $this->translate($store->getStatus()); ?>
                </span>
            </div>
		</td>
		<td>
			<div>
                <select class="store_action" onchange="performAction.call(this,<?php echo $store->id;?>)">
					<option value="">-select-</option>
                    <option value="manage_products" >manage products</option>
					<option value="edit" >edit</option>
					<?php if ($store->status != Core_Model_DbTable_Stores::STATUS_HIDDEN):?>
						<option value="hide">hide</option>
					<?php else:?>
						<option value="show">show</option>
					<?php endif;?>
					<option value="delete" >delete</option>
				</select>
			</div>
		</td>
	</tr>
	<?php endforeach;?>
</tbody>
</table>
<?php echo $this->paginationControl(
		$this->paginator,
		'Sliding',
		'store/pagination_control.phtml',
		array(
			'param_page'    => PARAM_PAGE_NAME,
			'query'         => isset($_GET[PARAM_SORT_DEFAULT])?array(PARAM_SORT_DEFAULT => $_GET[PARAM_SORT_DEFAULT]):array()
		)
	);
?>
<?php else:?>
<div class="sm_paginator_item_empty">
    <?php echo $this->translate('NO_STORE_AVAILABLE')?> - <a href="<?php echo $this->url(array('action'=>'create','id' => NULL));?>"><?php echo $this->translate('STORE_MENU_ITEM_CREATE') ?></a>
</div>
<?php endif;?>

<script language="javascript">
	$("a.tooltip").tipsy({html:true,gravity: $.fn.tipsy.autoNS});
    $(".tooltip_label").tipsy({html:true,gravity: $.fn.tipsy.autoNS});
	function performAction(id)
	{
		var backLink = '<?php echo base64_encode(urlencode($this->url(array()) . '?' . http_build_query($_GET))); ?>';

	   var action = this.value;
	   switch (action)
	   {
           case 'manage_products':
			   location.href="<?php echo $this->url(array('controller' => 'product','action' => 'list', 'page' => null)); ?>" + '/id_store/' + id + '/back_link/'+ backLink;
			   break;
		   case 'edit':
			   location.href="<?php echo $this->baseUrl('/store/store/edit/id/'); ?>" + id + '/back_link/'+ backLink;
			   break;
		   case 'show':
			   var ok = confirm('<?php echo $this->translate('MSG_CONFIRM_SHOW_STORE') ?>');
			   if (!ok) break;
			   location.href="<?php echo $this->baseUrl('/store/store/show/id/'); ?>" + id + '/back_link/'+ backLink;
			   break;
		   case 'hide':
			   var ok = confirm('<?php echo $this->translate('MSG_CONFIRM_HIDE_STORE') ?>');
			   if (!ok) break;
			   location.href="<?php echo $this->baseUrl('/store/store/hide/id/'); ?>" + id + '/back_link/'+ backLink;
			   break;
		   case 'delete':
			   var ok = confirm('<?php echo $this->translate('MSG_CONFIRM_DELETE_STORE') ?>');
			   if (!ok) break;
			   location.href="<?php echo $this->baseUrl('/store/store/delete/id/'); ?>  " + id + '/back_link/'+ backLink;;
				break;
		}
		this.selectedIndex = 0;
	}
</script>